/**
 * 
 * 移动零
 * https://leetcode-cn.com/problems/move-zeroes/
 * @param {number[]} nums
 * @return {void} Do not return anything, modify nums in-place instead.
 */
var moveZeroes = function (nums) {

    if (!nums || !nums.length) {
        return nums
    }
    let len = nums.length
    let zeroIndex = 0
    let i = 0
    // 从第一个0的位置开始替换
    while (i < len) {
        if (nums[i] !== 0) {
            let temp = nums[i]
            nums[i] = nums[zeroIndex]
            nums[zeroIndex++] = temp
        }
        i++
    }
};

let inputArr = [1, 2, 33, 3, 12]
moveZeroes(inputArr)
console.log(inputArr)

//================v3 要点总结===============
/**
 * 1. 这一版参考题解二，快排思想，直接交换0值和非零的值
 */